<template>
  <div class="mod-home">
    <div v-if="isRolad">
      <!-- <span v-if="unitType == 50">{{changeschoolname}} 类型：{{untTypeName}}</span> -->
      <!-- 代理商 -->
      <agentHomepage v-if="unitType == 50"></agentHomepage>
      <!-- 学校 -->
      <schoolHomepageFramework v-if="unitType == 100"></schoolHomepageFramework>
    </div>
  </div>
</template>

<script>
import schoolHomepageFramework from "@/components/school-homepage-framework";
import agentHomepage from "@/components/agent-homepage";
export default {
  data() {
    return {
      form: {
        name: "",
        schoolname: "",
      },
      dialogFormVisible: false,
      identity: "",
      userGuid: "",
      allschoollist: [],
      pageNum: 1,
      pageSize: 10,
      recordCount: 0,
      currentPage: 1,
      searchInfo: {},
      isRolad: true,
      // unitType:''
    };
  },
  components: {
    schoolHomepageFramework,
    agentHomepage,
  },
  created() {
    this.userType = sessionStorage.getItem("userType");
    this.userGuid = sessionStorage.getItem("administrator");
    this.unitType = sessionStorage.getItem("unitType");
    this.unitGuid = sessionStorage.getItem("unitGuid");
    this.unitGuid = this.$store.state.user.changeschoolid;
  },
  mounted() {
    if (!this.unitGuid) {
      this.allschool();
    }
  },
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid;
      },
    },
    changeschoolname: {
      get() {
        return this.$store.state.user.changeschoolname;
      },
    },
    untTypeName: {
      get() {
        return this.getUnitTypeName(this.$store.state.user.unitType);
      },
    },
    unitType: {
      get() {
        // alert(this.$store.state.user.changeschoolid)
        return this.$store.state.user.unitType;
      },
      set(value) {},
    },
  },
  watch: {
    "$store.state.user.changeschoolid": function (newFlag, oldFlag) {
      this.rolad();
    },
  },
  methods: {
    //管理获取学校
    allschool() {
      this.searchInfo.agentGuid = this.userGuid;
      if (this.unitType == "agentUnit") {
        this.searchInfo.unitType = 1; // 代理商单位
      } else {
        this.searchInfo.unitType = 2; // 普通单位
      }
      this.$http({
        url: this.$http.adornUrl("/manager/unit-info-page"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: this.searchInfo,
          },
          messageType: this.messageType,
        }),
      }).then(({ data }) => {
        console.log(data);
        if (data.messageCode == 200) {
          if (data.messageContent.data.length == 1) {
            this.set(data.messageContent.data[0].unitGuid);
            this.setnam(data.messageContent.data[0].unitName);
            this.setUnitType(data.messageContent.data[0].unitType);
            this.dialogFormVisible = false;
          }

          this.allschoollist = data.messageContent.data;
          this.recordCount = data.messageContent.recordCount;
          this.currentPage = data.messageContent.pageNum;
          this.searchInfo = {};
          //  console.log(this.allschoollist)
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    rolad() {
      this.isRolad = false;
      this.$nextTick(() => {
        this.isRolad = true;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.v-modal {
  z-index: 0;
}
.mod-home {
  line-height: 1.5;
  .cahnge_school {
    /deep/.el-dialog__body {
      padding: 10px 20px;
      // overflow-y:scroll;
      .el-form-item {
        margin-bottom: 0px;
        // padding-bottom: 10px;
        border-top: 1px solid #ccc;
        .dls_name {
          font-size: 20px;
        }
      }
      .el-form-item:nth-child(1) {
        border-top: 0px solid #ccc;
        margin-bottom: 20px;
      }
      .el-form-item:nth-child(3) {
        padding-bottom: 20px;
        padding-top: 30px;
      }
    }
  }
  .page {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>

